<script setup>
import { ref, onMounted, onUnmounted } from 'vue'

const images = [
  'https://picsum.photos/id/1015/1200/300',
  'https://picsum.photos/id/1016/1200/300',
  'https://picsum.photos/id/1018/1200/300'
]
const currentIndex = ref(0)

let timer = null

const startCarousel = () => {
  timer = setInterval(() => {
    currentIndex.value = (currentIndex.value + 1) % images.length
  }, 2000)
}

const stopCarousel = () => {
  clearInterval(timer)
}

onMounted(() => {
  startCarousel()
})

onUnmounted(() => {
  stopCarousel()
})
</script>

<template>
  <div class="dashboard-container">
    <div class="center-box">
      <h2 class="dashboard-title">欢迎您使用电子设备管理系统</h2>
      
      <div class="carousel-full" @mouseenter="stopCarousel" @mouseleave="startCarousel">
        <img :src="images[currentIndex]" alt="轮播图片" />
        <div class="carousel-indicators">
          <span
            v-for="(img, idx) in images"
            :key="idx"
            :class="{ active: idx === currentIndex }"
            @click="currentIndex = idx"
          ></span>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.dashboard-container {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f7fa;
  overflow: hidden; /* 禁止页面滚动 */
}
.center-box {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 0;
  background: transparent;
  box-shadow: none;
  position: relative;
}
.dashboard-title {
  margin-top: 48px;
  margin-bottom: 32rpx;
  font-size: 2.2rem;
  font-weight: bold;
  color: #409eff;
  text-shadow: 1px 2px 8px #b3d8ff;
  letter-spacing: 2px;
  background: rgba(255,255,255,0.85);
  padding: 16px 32px;
  border-radius: 12px;
  z-index: 2;
}
.carousel-full {
  width: 100vw;
  max-width: 100vw;
  height: 800px;
  overflow: hidden;
  position: absolute;
  left: 0;
  bottom: 0;
  border-radius: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}
.carousel-full img {
  width: 100vw;
  height: 100%;
  object-fit: cover;
  transition: opacity .5s;
}
.carousel-indicators {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
}
.carousel-indicators span {
  display: inline-block;
  width: 14px;
  height: 14px;
  background: #ddd;
  border-radius: 50%;
  cursor: pointer;
  transition: background .3s;
}
.carousel-indicators .active {
  background: #409eff;
}
</style>